class SearchIndexJob < ActiveJob::Base
  queue_as :search_index_job

  def perform(operation,type,id)

    obj=nil

    type.downcase!

    case type
      when 'topic'
        obj = Topic.find_by_id(id)
      when 'user'
        obj= User.find_by_id(id)
    end

    return false if !obj

  #   数据更新后更新对应的索引,防止索引到无效地址
    if operation == 'update'
      obj.__elasticsearch__.update_document
    elsif operation == 'index'
      obj.__elasticsearch__.index_document
    elsif operation  =='delete'
      obj.__elasticsearch__.delete_document
    end
  end
end
